package model;

import model.game.Player;
import model.game.Skill;
import model.game.skills.Itself;

public class Human {

    public Player me;
    public Player other;
    private BattleBalance move;

    public Human(Player me, Player other) {
        this.me = me;
        this.other = other;
    }

    public String move(Skill skill) {
        int d;
        move = new BattleBalance(me, other);
        d = move.move(skill, 0);
        if (d==-1){
            return me.getName()+ " usou " +skill.getName().toLowerCase() + ". "+other.getName()+ " escapou do golpe.";
        }else if (d==-2){
            if (skill instanceof Itself){
                Itself i = (Itself) skill;
                return me.getName()+ " usou " +skill.getName().toLowerCase() + ". "+me.getName()+ " recuperou " + i.getAmount()+" de vida.";
            }
            return "error";
        }else if (d==-99){
            return me.getName()+ "Skill inválida. Perdeu seu turno otário.";
        }else{
            setLife(other, d);
            return me.getName()+ " usou " +skill.getName().toLowerCase() + ". "+other.getName()+ " tomou " + d + " de dano";
        }
    }

    public boolean evasion(int valorAtaque, int valorDefesa) {
        int dadoDef = 1 + (int) (Math.random() * valorDefesa);
        int dadoAtk = 1 + (int) (Math.random() * valorAtaque);
        if (dadoDef > dadoAtk) {
            return true;
        } else {
            return false;
        }
    }

    public int damage(int valorAtaque, int valorDefesa) {
        int dadoatk = 1 + (int) (Math.random() * 6);
        int dadodef = 1 + (int) (Math.random() * 6);
        return valorAtaque + dadoatk - valorDefesa - dadodef;
    }

    public Player getPlayer() {
        return me;
    }

    public void setLife(Player p, int damage) {
        p.setLife(p.getLife() - damage);
    }

    public void setEnergy(Player p, int used) {
        p.setEnergy(p.getEnergy() - used);
    }

    public int getLife(Player p) {
        return p.getLife();
    }

    public int getEnergy(Player p) {
        return p.getEnergy();
    }

    public String getName(Player p) {
        return p.getName();
    }

    public int getId(Player p) {
        return p.getId();
    }

    public int getStrength(Player p) {
        return p.getStrength();
    }

    public int getResistence(Player p) {
        return p.getResistence();
    }

    public int getFirePower(Player p) {
        return p.getFirePower();
    }

    public int getAgility(Player p) {
        return p.getAgility();
    }

    public int getArmor(Player p) {
        return p.getArmor();
    }
}
